
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once

#include "RTMaterialComponent.h"



namespace RT
{
	//forward declarations
	class RTIProcTexture;
	class RTTexture;

	/*Material for a primitive.*/
	class RTMaterial
	{
	private:
		//represent the ambient component of the material
		RTMaterialComponent _ambient;

		//represent the diffuse component of the material
		RTMaterialComponent _diffuse;

		//represent the specular component of the material
		RTMaterialComponent _specular;

	
	public:
		//Specular color
		F32 m_shininess;

		//reflection
		RTColor m_reflect;

		//refraction coefficient
		F64 m_refractionIndex;

	private:
		//Procedural texture used as bump map
		RTIProcTexture* m_bumpMap;
		
		/*Texture used as diffuse*/
		RTTexture* m_diffuseTexture;

	public:
		//constructor
		RTMaterial();

		//destructor
		virtual ~RTMaterial();

		//set the ambient component using a color
		void setAmbient(const RTColor& ambient);

		//set the ambient component using a procedural texture
		void setAmbient(RTIProcTexture* const procTexture);

		//set the ambient component using a texture from a file
		void setAmbient(RTTexture* const fromFileTexture);

		//set the diffuse component using a color
		void setDiffuse(const RTColor& diffuse);

		//set the diffuse component using a procedural texture
		void setDiffuse(RTIProcTexture* const procTexture);

		//set the diffuse component using a file texture
		void setDiffuse(RTTexture* const fromFileTexture);

		//set the specular component using a color
		void setSpecular(const RTColor& specular);

		//set the specular component using a procedural texture
		void setSpecular(RTIProcTexture* const procTexture);

		//set the specular component using a file texture
		void setSpecular(RTTexture* const fromFileTexture);

		//set the bump map
		void setBumpMap(RTIProcTexture* bump);

		//Return the diffuse color of the component on the poI32 v in the RTPrimitive p.
		RTColor getDiffuse(const RTVector3f& v, const RTIPrimitive& p)const;

		//Return the ambient color of the component on the poI32 v in the RTPrimitive p.
		RTColor getAmbient(const RTVector3f& v, const RTIPrimitive& p)const;

		//Return the specular color of the component on the poI32 v in the RTPrimitive p.
		RTColor getSpecular(const RTVector3f& v, const RTIPrimitive& p)const;

		//return the normal of the point using a bump mapping texture
		RTVector3f getBumpNormal(const RTVector3f& v)const;

		//Check if this material use a bump map
		bool useBumpMapping()const;

	};

}